    package filter;
    import bean.User;
    import javax.servlet.*;
    import javax.servlet.annotation.WebFilter;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    import java.io.IOException;

    @WebFilter(filterName = "loginFilter",urlPatterns = {"/*"})
    public class loginFilter implements Filter {
        @Override
        public void destroy() {
        }
        public void init(FilterConfig config) throws ServletException {

        }

        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
            HttpServletRequest req = (HttpServletRequest) request;
            HttpServletResponse res = (HttpServletResponse) response;

            Object LocalUser = req.getSession().getAttribute("LocalUser");
            if(req.getRequestURI().contains("Login.jsp")||req.getRequestURI().contains("register.jsp")||req.getRequestURI().contains("/Login_C")||req.getRequestURI().contains("/Register")||req.getRequestURI().contains("/UploadServlet")||LocalUser!=null||req.getRequestURI().endsWith(".css")||req.getRequestURI().endsWith(".html")
                    ||req.getRequestURI().contains("usercenter.jsp")||req.getRequestURI().contains("error.jsp")||req.getRequestURI().contains("/css/")||req.getRequestURI().contains("/fonts/")||req.getRequestURI().contains("/images/")||req.getRequestURI().contains("/js/")||req.getRequestURI().contains("/login/dgut"))
            {
                chain.doFilter(req,res);
            }
            else{
                if(LocalUser==null){
                    res.sendRedirect("/Login.jsp");
                }else{
                    chain.doFilter(req,res);
                }
            }
        }

    }
